package com.binance.binancedemo.fragment

import android.os.Bundle
import android.os.Handler
import android.support.v4.app.Fragment
import android.view.View
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

/**
 * Created by xiangchong on 2017/12/15.
 */
abstract class BaseFragment:Fragment(){

    private var mCompositeDisposable : CompositeDisposable? = null


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val handler = Handler()
        view.post { handler.post { onFirstFrameVisible() } }
    }

     abstract fun onFirstFrameVisible()


    fun addDisposable(disposable: Disposable) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = CompositeDisposable()
        }
        mCompositeDisposable?.add(disposable)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        disposableAll()
    }

    private fun disposableAll() {
        mCompositeDisposable?.dispose()
        mCompositeDisposable = null
    }

}
